﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>供应商列表</title>
    <link href="~/lib/layui/css/layui.css" rel="stylesheet" />
    @* <script src="~/lib/layui/layui.js"></script> *@
    <script src="~/js/js.cookie.js"></script>
    <script src="~/js/moment.js"></script>
    <script src="~/lib/jquery/dist/jquery.js"></script>
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
            <div class="demo-Add-container">
                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            出库单编号
                        </div>
                        <div style="width:300px;left:28px">
                            <input style="width:300px" type="text" id="sellStockNo" value="" lay-verify="required" placeholder="请输入出库单编号" lay-reqtext="请填写出库单编号" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>

                        <div class="layui-input-prefix" style="left:110px">
                            出库单名称
                        </div>
                        <div style="width:300px;left:110px">
                            <input style="width:300px" type="text" id="sellStockName" value="" lay-verify="required" placeholder="请输入出库单名称" lay-reqtext="请填写出库单名称" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:14px">
                            销售订单编号
                        </div>
                        <div style="width:200px;left:14px">
                            <input style="width:200px" type="text" id="sellStockIndent" value="" lay-verify="required" placeholder="请输入销售订单编号" lay-reqtext="请填写销售订单编号" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>

                        <div class="layui-input-prefix" style="left:20px">
                            客户编码
                        </div>
                        <div style="width:150px;left:20px">
                            <input style="width:150px" type="text" id="clientNo" value="" lay-verify="required" placeholder="请输入客户编码" lay-reqtext="请填写客户编码" autocomplete="off" class="layui-input" lay-affix="clear">

                        </div>
                        <div style="left:19px">
                            <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-customs">
                                <i class="layui-icon layui-icon-search"></i>
                            </button>
                        </div>

                        <div class="layui-input-prefix" style="left:87px">
                            客户名称
                        </div>
                        <div style="width:200px;left:82px">
                            <input style="width:200px" type="text" id="clientName" value="" lay-verify="required" placeholder="请输入客户名称" lay-reqtext="请填写客户名称" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:42px">
                            出库日期
                        </div>
                        <div style="width:220px;left:43px">
                            <input style="width:210px" type="date" id="sellStockTime" value="" lay-verify="required" placeholder="请输入出库日期" lay-reqtext="请填写出库日期" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>

                        <div class="layui-input-prefix" style="left:28px">
                            单据状态
                        </div>
                        <div style="width:200px;left:28px">
                            <select style="width:200px" id="sellStockStart">
                                <option value="0">草稿</option>
                                <option value="1">已确认</option>
                                <option value="2">审批中</option>
                                <option value="3">已审批</option>
                                <option value="4">已完成</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:70px">
                            备注
                        </div>
                        <div style="width:780px;left:72px">
                            <textarea style="width:780px" type="textarea" id="sellStockRemark" value="" lay-verify="required" placeholder="请输入内容" lay-reqtext="请填写销售出库备注" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                        </div>
                    </div>
                </div>
                
                <div align="center">
                    <h1>物料信息</h1>
                </div>
                <hr/>

                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue" lay-on="test-page-custom">
                                <i class="layui-icon layui-icon-add-1">新增</i>
                            </button>
                        </div>
                    </div>
                </div>

                <table style="left:320px" class="layui-hide" id="ID-table-demo-datas" lay-filter="ID-table-demo-datas"></table>

                <div class="layui-form-item" style="left:755px">
                    <button class="layui-btn layui-btn-normal" onclick="UpdateSellStock()">修改</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
            <a class="layui-btn layui-btn-xs" lay-event="YesWang">选择</a>
        </div>
    </script>
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>

    <script>
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;
        layui.use(function () {
            // 事件
            util.on('lay-on', {
                'test-page-custom': function () {
                    layer.open({
                        type: 1,
                        area: '100%',
                        resize: false,
                        shadeClose: true,
                        title: '添加销售出库单',
                        content: `
                        <form class="layui-form" action="">
                            <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                                <div class="demo-Add-container">
                                    <div class="layui-form-item">
                                        <div class="layui-input-group">
                                            <div class="layui-input-prefix" style="left:28px">
                                                产品编码
                                            </div>
                                            <div style="width:200px;left:28px">
                                                <input style="width:200px" type="text" id="productManageNode" value="" lay-verify="required" placeholder="请输入产品编码" lay-reqtext="请填写产品编码" autocomplete="off" class="layui-input" lay-affix="clear">
                                            </div>
                                            <div style="left:27px">
                                                <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-customsed">
                                                    <i class="layui-icon layui-icon-search"></i>
                                                </button>
                                            </div>
                                            <div class="layui-input-prefix" style="left:90px">
                                                产品名称
                                            </div>
                                            <div style="width:200px;left:90px">
                                                <input style="width:200px" type="text" id="productManageName" value="" lay-verify="required" placeholder="请输入产品名称" lay-reqtext="请填写产品名称" autocomplete="off" class="layui-input" lay-affix="clear">
                                            </div>
                                            <div class="layui-input-prefix" style="left:120px">
                                                单位
                                            </div>
                                            <div style="width:200px;left:120px">
                                                <input style="width:200px" type="text" id="unites" value="" lay-verify="required" placeholder="请输入单位" lay-reqtext="请填写单位" autocomplete="off" class="layui-input" lay-affix="clear">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-input-group">
                                            <div class="layui-input-prefix" style="left:29px">
                                                规格型号
                                            </div>
                                            <div style="width:878px;left:29px">
                                                <textarea style="width:878px" type="textarea" id="productManageNumber" value="" lay-verify="required" placeholder="请输入内容" lay-reqtext="请填写规格型号" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                                            </div>
                                        </div>
                                    </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:28px">
                                            仓库
                                        </div>
                                        <div style="width:200px;left:28px">
                                            <input style="width:200px" type="text" id="StashName" value="" lay-verify="required" placeholder="请输入仓库" lay-reqtext="请填写仓库" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:14px">
                                            批次号
                                        </div>
                                        <div style="width:200px;left:14px">
                                            <input style="width:200px" type="text" id="ProductsSaleBuer" value="" lay-verify="required" placeholder="请输入批次号" lay-reqtext="请填写批次号" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                        <div class="layui-input-prefix" style="left:20px">
                                            生产工单
                                        </div>
                                        <div style="width:150px;left:20px">
                                            <input style="width:150px" type="text" id="productionWorkOrdersNo" value="" lay-verify="required" placeholder="请输入生产工单" lay-reqtext="请填写生产工单" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                        <div class="layui-input-prefix" style="left:87px">
                                            出库数量
                                        </div>
                                        <div style="width:200px;left:82px">
                                            <input style="width:200px" type="text" id="ProductsSaleNum" value="" lay-verify="required" placeholder="请输入出库数量" lay-reqtext="请填出库数量" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:70px">
                                            备注
                                        </div>
                                        <div style="width:780px;left:72px">
                                            <textarea style="width:780px" type="textarea" id="ProductsSaleDemand" value="" lay-verify="required" placeholder="请输入内容" lay-reqtext="请填写备注" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item" style="left:755px">
                                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="demo-Add">保存</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                            </div>
                        </form>
                        `,
                        success: function () {
                            // 对弹层中的表单进行初始化渲染
                            form.render();
                            // 表单提交事件
                            form.on('submit(demo-Add)', function (data) {
                                var field = data.field; // 获取表单字段值
                                var datec = new Date()
                                var year = datec.getFullYear();
                                var month = (datec.getMonth() + 1).toString().padStart(2, "0")
                                var date = (datec.getDate() + 1).toString().padStart(2, "0")
                                var hours = datec.getHours()
                                var minute = (datec.getMinutes()).toString().padStart(2, "0")
                                var seconds = (datec.getSeconds()).toString().padStart(2, "0")
                                // var Encoding = "IF";
                                var result = "CX" + year + month + date + hours + minute + seconds;
                                console.log(result);
                                //获取name数据
                                let first = {
                                    productsSaleNo: result,
                                    materialNo:localStorage.getItem("materialNo"),
                                    productionWorkOrdersNo:$("#productionWorkOrdersNo").val(),
                                    stashId: localStorage.getItem("stashId"),
                                    productsSaleYesNo:0,
                                    productsSaleDemand: $("#ProductsSaleDemand").val(),
                                    sellStockNo:localStorage.getItem("sellStockNo"),
                                    productManageNode: $("#productManageNode").val(),
                                    productsSaleNum: $("#ProductsSaleNum").val(),
                                    productsSaleBuer: $("#ProductsSaleBuer").val(),
                                };
                                console.log("##!!!");
                                // 显示填写结果，仅作演示用
                                // layer.alert(JSON.stringify(field), {
                                //     title: '当前填写的字段值'
                                // });
                                // 此处可执行 Ajax 等操作
                                // …
                                $.ajax({
                                    url: '@ViewBag.FoundationWrite' + "/api/UserLi/CreateProductsSale",
                                    data: JSON.stringify(first),
                                    type: "post",
                                    async: true,
                                    dataType: "json",
                                    contentType: "application/json",
                                    success: res => {
                                        if (res.code > 0) {
                                            alert('新增成功');
                                            layer.closeAll(); // 关闭当前弹层
                                        }
                                        else {
                                            alert('新增失败');
                                        }
                                    }
                                })
                                return false; // 阻止默认 form 跳转
                            });
                        }
                    });
                }
            })
        });
    </script>

    <script>
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;
        layui.use(function () {
            // 事件
            util.on('lay-on', {
                'test-page-customsed': function () {
                    layer.open({
                        type: 1,
                        area: '100%',
                        resize: false,
                        shadeClose: true,
                        title: '库存物资选择',
                        content: `
                        <form class="layui-form" action="">
                            <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                                <div class="layui-form-item">
                                    <div class="demo-Add-container">
                                        <table style="left:320px" class="layui-hide" id="ID-table-demo-datasd" lay-filter="ID-table-demo-datasd"></table>
                                    </div>
                                </div>
                            </div>
                        </form>
                        `,
                        success: function () {
                            var form = layui.form;
                            var laypage = layui.laypage;
                            var layer = layui.layer;
                            var $ = layui.$;
                            var laydate = layui.laydate;
                            var util = layui.util;

                            //文档就绪函数
                            $(function () {
                                ProductsSales(1, 100);
                            })


                            //生产报工列表
                            function ProductsSales(pageIndex, pageSize) {
                                let obj = {
                                    pageIndex: pageIndex,
                                    pageSize: pageSize
                                }
                                var inst = table.render({
                                    elem: '#ID-table-demo-datasd',
                                    method: 'post',
                                    contentType: 'application/json',
                                    toolbar: '#toolbarDemo',
                                    defaultToolbar: ['filter', 'exports', 'print', { // 右上角工具图标
                                        title: '提示',
                                        layEvent: 'LAYTABLE_TIPS',
                                        icon: 'layui-icon-tips',
                                        onClick: function (obj) { // 2.9.12+
                                            layer.alert('自定义工具栏图标按钮');
                                        }
                                    }],
                                    url: '@ViewBag.FoundationRead' + '/api/UserLi/SearchMaterial',
                                    where: obj,
                                    cols: [[
                                        { field: 'productManageNode', title: '产品物料编码', width: 120 },
                                        { field: 'productManageName', title: '产品物料名称', width: 120 },
                                        { field: 'productManageNumber', title: '规格型号', width: 120 },
                                        { field: 'unites', title: '单位', width: 120 },
                                        { field: 'stashName', title: '仓库名称', width: 120 },
                                        { field: 'stickWorkNum', title: '在库数量', width: 80 },
                                        { field: 'stockWorkTime', title: '库存有效期', width: 120 },
                                        { fixed: 'right', title: '操作', width: 140, minWidth: 140, templet: '#toolDemo' }
                                    ]],
                                    page: false,
                                    height: 310,
                                    done: function (res) {
                                        var id = this.id;
                                        console.log(res);// 你可以在这里检查返回的数据结构是否符合预期
                                        // 触发单元格工具事件
                                        //分页数据
                                        laypage.render({
                                            elem: 'demo-laypage-alles', // 元素 id
                                            count: res.totalCount, // 数据总数
                                            curr: pageIndex,
                                            limit: pageSize,
                                            limits: [2, 3, 4],
                                            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                                            jump: function (obj, first) {
                                                if (!first) {
                                                    ProductionSearch(obj.curr, obj.limit);
                                                }
                                            }
                                        });
                                    }
                                })
                                table.on('tool(ID-table-demo-datasd)', function (obj) { // 双击 toolDouble
                                    var data = obj.data; // 获得当前行数据
                                    console.log(data)
                                    if (obj.event === 'YesWang') {
                                        $("#productManageNode").val(data.productManageNode);
                                        $("#productManageName").val(data.productManageName);
                                        $("#unites").val(data.unites);
                                        $("#productManageNumber").val(data.productManageNumber);
                                        $("#StashName").val(data.stashName);
                                        $("#ProductsSaleNum").val(data.stickWorkNum);
                                        localStorage.setItem("materialNo", data.materialNo);
                                        localStorage.setItem("stashId", data.stashId);
                                        // 对弹层中的表单进行初始化渲染
                                        form.render();
                                        layer.close(layer.index); // 关闭弹层
                                    }
                                });
                            }
                            

                            // 对弹层中的表单进行初始化渲染
                            form.render();
                            // 表单提交事件
                            form.on('submit(demo-Search)', function (data) {
                                var field = data.field; // 获取表单字段值

                                // 显示填写结果，仅作演示用
                                // layer.alert(JSON.stringify(field), {
                                //     title: '当前填写的字段值'
                                // });
                                // 此处可执行 Ajax 等操作
                                // …

                                return false; // 阻止默认 form 跳转
                            });
                        }
                    });
                }
            })
        });
    </script>

</body>
</html>
<script>
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    layui.use(function () {
        // 事件
        util.on('lay-on', {
            'test-page-customs': function () {
                layer.open({
                    type: 1,
                    area: '100%',
                    resize: false,
                    shadeClose: true,
                    title: '客户选择',
                    content: `
                    <form class="layui-form" action="">
                        <div class="layui-form">
                            <div class="demo-Search-container">
                            <div class="layui-form-item">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix">
                                        客户编码
                                    </div>
                                    <div>
                                        <input id="ClientNoed" type="text" placeholder="请输入客户编码" class="layui-input">
                                    </div>

                                    <div class="layui-input-prefix" style="left:50px">
                                        客户名称
                                    </div>
                                    <div style="left:50px">
                                        <input id="ClientNamed" type="text" placeholder="请输入客户名称" class="layui-input">
                                    </div>

                                    <div class="layui-input-prefix" style="left:100px">
                                        客户简称
                                    </div>
                                    <div style="left:100px">
                                        <input id="ClientAName" type="text" placeholder="请输入客户简称" class="layui-input">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix" style="left:14px">
                                        客户英文名称
                                    </div>
                                    <dic style="left:14px">
                                        <input id="ClientEname" type="text" placeholder="请输入客户英文名称" class="layui-input">
                                    </dic>

                                    <div class="layui-input-prefix" style="left:77px">
                                        是否启用
                                    </div>
                                    <div style="left:77px;width:197px">
                                        <select id="IsVaild" lay-filter="testSelect">
                                            <option value="-1">是否启用</option>
                                            <option value="0">禁用</option>
                                            <option value="1">启用</option>
                                        </select>
                                    </div>

                                    <div style="left:150px">
                                        <button onclick="ShowSupplier()" id="searchBtn" type="button" class="layui-btn layui-btn-normal">搜索</button>

                                    </div>

                                    <div style="left:170px">
                                        <button onclick="Break()" type="button" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </div>

                            <table style="left:320px" class="layui-table">
                                <thead>
                                    <tr>
                                        <td>客户编号</td>
                                        <td>客户名称</td>
                                        <td>客户简称</td>
                                        <td>客户类型</td>
                                        <td>客户电话</td>
                                        <td>客户联系人</td>
                                        <td>客户联系人电话</td>
                                        <td>是否启用</td>
                                        <td>操作</td>
                                    </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                            <div id="demo-laypage-alls"></div>
                            </div>
                        </div>
                    </form>
                    `,
                    success: function () {
                        var form = layui.form;
                        var laypage = layui.laypage;
                        var layer = layui.layer;
                        var $ = layui.$;
                        var laydate = layui.laydate;
                        var util = layui.util;

                        var pageIndex = 1;
                        var pageSize = 2;

                        $(function () {
                            ShowSupplier(pageIndex, pageSize);
                        })

                        // 获取客户编码
                        $('#searchBtn').click(function () {
                            var supplier = $('#clientNoed').val();
                            ShowSupplier(pageIndex, pageSize)
                        });
                        // 获取客户名称
                        $('#searchBtn').click(function () {
                            var supplier1 = $('#clientNamed').val();
                            ShowSupplier(pageIndex, pageSize)
                        });
                        //客户简称
                        $('#searchBtn').click(function () {
                            var supplier2 = $('#clientAName').val();
                            ShowSupplier(pageIndex, pageSize)
                        });
                        // 英文名称
                        $('#searchBtn').click(function () {
                            var supplier2 = $('#clientEname').val();
                            ShowSupplier(pageIndex, pageSize)
                        });
                        //是否启用
                        form.on('select(testSelect)', function (data) {
                            ShowPermission(data.value); // data.value
                        });
                        var clientNo = $("#clientNoed").val() || "";
                        var clientName = $("#clientNamed").val() || "";
                        var clientAName = $("#clientAName").val() || "";
                        var clientEname = $("#clientEname").val() || "";
                        var isVaild = $("#isVaild").val() || -1;

                        function ShowSupplier(index, size) {
                            console.log(clientNo, clientName, clientAName, clientEname, isVaild);
                            $.ajax({
                                url: '@ViewBag.FoundationWrite' + '/api/Jocker/ClientManagementList',
                                data: JSON.stringify({ clientNo: clientNo, clientName: clientName, clientAName: clientAName, clientEname: clientEname, isVaild: isVaild, pageIndex: index, pageSize: size }),
                                type: "post",
                                async: false,
                                dataType: "json",
                                contentType: "application/json",
                                success: res => {
                                    var tbody = $("tbody");
                                    tbody.empty();
                                    if (res.data != null) {
                                        console.log(res.data);
                                        $.each(res.data, function () {
                                            tbody.append(`<tr>
                                                <td>${this.clientNo}</td>
                                                <td>${this.clientName}</td>
                                                <td>${this.clientAName}</td>
                                                <td>${this.clientTypeName}</td>
                                                <td>${this.clientPhone}</td>
                                                <td>${this.clientContact1}</td>
                                                <td>${this.clientPhone1}</td>
                                                <td>${this.isVaild === 1 ? '启用' : '禁用'}</td>
                                                <td><a onclick="GetClient(${this.clientId},'${this.clientNo}','${this.clientName}')" class="btn btn-link">选择</a></td>
                                                </tr>`);
                                        });
                                    }
                                    form.render(); // 重新渲染下拉框
                                    //完整显示
                                    laypage.render({
                                        elem: 'demo-laypage-alls', // 元素 id
                                        count: res.totalCount, // 数据总数
                                        curr: index,//当前页
                                        limit: size,//每页几条
                                        limits: [2, 3, 4],
                                        layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                                        jump: function (obj, first) {
                                            if (!first) {
                                                ShowSupplier(obj.curr, obj.limit);
                                            }
                                        }
                                    });
                                }
                            })
                        }

                        // 对弹层中的表单进行初始化渲染
                        form.render();
                        // 表单提交事件
                        form.on('submit(demo-Search)', function (data) {
                            var field = data.field; // 获取表单字段值 

                            // 显示填写结果，仅作演示用
                            // layer.alert(JSON.stringify(field), {
                            //     title: '当前填写的字段值'
                            // });
                            // 此处可执行 Ajax 等操作
                            // …

                            return false; // 阻止默认 form 跳转
                        });
                    }
                });
            }
        })
    });
    function GetClient(clientId, clientNo, clientName) {

        localStorage.setItem("clientId", clientId);
        $('#clientNo').val(clientNo);
        $('#clientName').val(clientName);
        layer.close(layer.index); // 关闭弹层
        form.render(); // 重新渲染
    }
</script>




<script>
    //文档就绪函数
   
    var table = layui.table;
    var $ = layui.$;
    var form = layui.form;
    var laydate = layui.laydate;
    var util = layui.util;
    var layer = layui.layer;
    var laypage = layui.laypage;

    //生产报工列表
    function ProductsSale(pageIndex, pageSize) {
        form.render();
        let obj = {
            sellStockNo: $('#sellStockNo').val(),
            pageIndex: pageIndex,
            pageSize: pageSize
        }
        var inst = table.render({
            elem: '#ID-table-demo-datas',
            method: 'post',
            contentType: 'application/json',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', { // 右上角工具图标
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips',
                onClick: function (obj) { // 2.9.12+
                    layer.alert('自定义工具栏图标按钮');
                }
            }],
            url: '@ViewBag.FoundationRead' + '/api/UserLi/SearchProductsSale',
            where: obj,
            cols: [[
                { field: 'productManageNode', title: '产品编号', width: 120 },
                { field: 'productManageName', title: '产品名称', width: 120 },
                { field: 'productManageNumber', title: '规格型号', width: 120 },
                { field: 'unites', title: '单位', width: 120 },
                { field: 'productsSaleNum', title: '出库数量', width: 120 },
                { field: 'productsSaleBuer', title: '批次号', width: 120 },
                { field: 'stashName', title: '仓库名称', width: 80 },
                { field: 'productsSaleDemand', title: '备注', width: 120 },
            ]],
            page: false,
            height: 310,
            done: function (res) {
                var id = this.id;
                console.log(res);// 你可以在这里检查返回的数据结构是否符合预期
                // 触发单元格工具事件
                //分页数据
                laypage.render({
                    elem: 'demo-laypage-alles', // 元素 id
                    count: res.totalCount, // 数据总数
                    curr: pageIndex,
                    limit: pageSize,
                    limits: [2, 3, 4],
                    layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                    jump: function (obj, first) {
                        if (!first) {
                            ProductionSearch(obj.curr, obj.limit);
                        }
                    }
                });
            }
        })
    }
</script>

<script>
    var form = layui.form;
    var laypage = layui.laypage;
    var layer = layui.layer;
    var $ = layui.$;
    var laydate = layui.laydate;
    var util = layui.util;
    var obj = {
        sellStockId: 0,
        sellStockNo: '',
        sellStockName: '',
        sellStockIndent: '',
        clientNo: '',
        clientName: '',
        sellStockTime: '',
        sellStockStart: '',
        sellStockRemark: '',
    };
    $(function () {
        Backfill()
    })

    function Backfill() {
        return new Promise(function (resolve, reject) {
            $(document).ready(function () {
                //获取要编辑的销售出库单id，可以通过url参数传递
                var sellstockId = localStorage.getItem("sellStockId");
                console.log(sellstockId);
                //根据id获取销售出库单信息
                if (sellstockId) {
                    $.ajax({
                        type: 'post',
                        url: '@ViewBag.FoundationRead' + "/api/UserLi/BackfillSellStock",
                        data: JSON.stringify({ sellStockId: sellstockId }),
                        async: false,
                        dataType: "json",
                        contentType: "application/json",
                        success: function (res) {

                            if (res.data) {
                                const sellStock = res.data;
                                console.log(sellStock);
                                $('#sellStockNo').val(sellStock[0].sellStockNo);
                                $('#sellStockName').val(sellStock[0].sellStockName);
                                $('#sellStockIndent').val(sellStock[0].sellStockIndent);
                                $('#clientNo').val(sellStock[0].clientNo);
                                $('#clientName').val(sellStock[0].clientName);
                                $('#sellStockTime').val(moment(sellStock[0].sellStockTime).format('YYYY-MM-DD'));
                                $('#sellStockStart').val(sellStock[0].sellStockStart);
                                layui.form.render('select');
                                $('#sellStockRemark').val(sellStock[0].sellStockRemark);
                                ProductsSale(1, 2);
                                resolve(sellStock);

                            } else {
                                layer.msg(res.message);
                            }
                            form.render();
                        }
                    })
                }
            })
        })
    }
    function UpdateSellStock() {

        //获取要编辑的销售出库单id，可以通过url参数传递
        var sellstockId = localStorage.getItem("sellStockId");
        let first = {
            sellStockId: sellstockId,
            sellStockNo: $('#sellStockNo').val(),
            sellStockName: $('#sellStockName').val(),
            sellStockIndent: $('#sellStockIndent').val(),
            clientId: localStorage.getItem("clientId"),
            sellStockTime: $('#sellStockTime').val(),
            sellStockStart: $('#sellStockStart').val(),
            sellStockRemark: $('#sellStockRemark').val(),
            ProductsSaleId: 0,
        };
        console.log(first);
        $.ajax({
            url: '@ViewBag.FoundationWrite' + "/api/UserLi/UpdateSellStock",
            data: JSON.stringify(first),
            type: "post",
            async: true,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                if (res.code > 0) {
                    alert('修改成功');
                    layer.closeAll(); // 关闭当前弹层
                }
                else {
                    alert('修改失败');
                }
            }

        })
    }
</script>